package com.example.food.controller;

import com.example.food.bean.Goods;
import com.example.food.repository.GoodsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class GoodsController {

    @Autowired
    GoodsRepository goodsRepository;

    @GetMapping("/goods")
    public String findAllGoods(Model model) {
        //获取所以用户
        List<Goods> goodss = goodsRepository.findAll();
        //放入请求域中
        model.addAttribute("gs", goodss);
        return "goods/table_goods";
    }

    @GetMapping("/good_cc")
    public String findByCateCC(Model model) {
        //查出
        List<Goods> goods = goodsRepository.findByGoodCategory("川菜");
        //
        model.addAttribute("gs", goods);
        return "goods/table_goods";
    }

    @GetMapping("/good_yc")
    public String findByCateYC(Model model) {
        //查出
        List<Goods> goods = goodsRepository.findByGoodCategory("粤菜");
        //
        model.addAttribute("gs", goods);
        return "goods/table_goods";
    }

    @GetMapping("/good_mc")
    public String findByCateMC(Model model) {
        //查出
        List<Goods> goods = goodsRepository.findByGoodCategory("闽菜");
        //
        model.addAttribute("gs", goods);
        return "goods/table_goods";
    }

    @GetMapping("/good_tp")
    public String findByCateTP(Model model) {
        //查出
        List<Goods> goods = goodsRepository.findByGoodCategory("甜品");
        //
        model.addAttribute("gs", goods);
        return "goods/table_goods";
    }

    @GetMapping("/good_tl")
    public String findByCateTL(Model model) {
        //查出
        List<Goods> goods = goodsRepository.findByGoodCategory("汤类");
        //
        model.addAttribute("gs", goods);
        return "goods/table_goods";
    }

    @GetMapping("/good_sk")
    public String findByCateSC(Model model) {
        //查出
        List<Goods> goods = goodsRepository.findByGoodCategory("烧烤");
        //
        model.addAttribute("gs", goods);
        return "goods/table_goods";
    }

    @GetMapping("/good_sx")
    public String findByCateSX(Model model) {
        //查出
        List<Goods> goods = goodsRepository.findByGoodCategory("沙县小吃");
        //
        model.addAttribute("gs", goods);
        return "goods/table_goods";
    }

    @RequestMapping("/delete")
    public String d() {
        //

        return "";
    }
}
